<template>
  <div class="home">
      

      {{$store.state.token}}
  </div>
</template>

<script>
// 打开public下的文件
// window.open('vue_test.html')

// import electron from 'electron'




export default {
  components: {},
  data() {
    return {};
  },
  mounted() {
      
    // 请求数据，赋值数据 等等一系列操作...
    // 监听窗口发生变化，resize组件
  window.addEventListener('setItem', ()=> {
        this.newVal = sessionStorage.getItem('watchStorage');
        var data=JSON.parse(this.newVal)
         console.log(data)
})
  },
  created() {
      setInterval(() => {
        //    this.newVal = sessionStorage.getItem('watchStorage');
        // var data=JSON.parse(this.newVal)
        //  console.log(data)

         var cookies = document.cookie.split(";");
console.log(cookies);
      }, 2000);
      
//       setTimeout(() => {
//     this.$store.commit('setToken','22')
// }, 3000);
    // var socket = new WebSocket("ws://127.0.0.1:39121/");

    // socket.onopen = function () {
    //     //do something when connection estabilished
    //     console.log(222)
    // };

    // socket.onmessage = function (message) {
    //     //do something when message arrives
    //     console.log("Connection open ...");
    //     socket.send("发送的数据");
    // };

    // socket.onclose = function () {
    //     //do something when connection close
    // };

    // const { ipcRenderer } = window.require("electron").default();

    this.$utools.onPluginReady(() => {
      console.log("插件装配完成，已准备好");
      this.$utools.onPluginEnter(({ code, type, payload }) => {
        console.log("用户进入插件", code, type, payload);
        console.log("111");
        if (window.ubWindow) {
          // && window.ubWindow.isNormal()
          console.log(window.ubWindow.hasOwnProperty("isEnabled"));
          console.log(window.ubWindow.isEnabled());

          window.ubWindow.show();
          return;
        }
        console.log(111);
        window.ubWindow = this.$utools.createBrowserWindow(
          "/index.html",
          {
            show: false,
            title: "测试窗口",
            width: 1800,
            height: 900,
            frame: false,
            nodeIntegration: true,
            //使用远程模块必须开启此处
            enableRemoteModule: true,
            webPreferences: {
              preload: "preload.js",
            },
          },
          () => {
            console.log(window.uilt);

            // const { globalShortcut } = require('electron')
            // 显示
            ubWindow.show();
            // 打开调试
            ubWindow.webContents.openDevTools();
            // 置顶
            // ubWindow.setAlwaysOnTop(true);
            // 窗口全屏
            // ubWindow.setFullScreen(true);
            // 全局快捷键(测试可用) 唤起
            // require("electron").register('CommandOrControl+alt+k', () => {
            //     //检测到快捷键唤起主页面
            //     ubWindow.show();
            //     //发送消息给渲染层
            ubWindow.setSkipTaskbar(false);
            ubWindow.setClosable(false);
            //     // mainWindow.webContents.send('main-process-messages', 'show_window');
            //     console.log('CommandOrControl+L is pressed')
            // })

            // this.$utools.onPluginOut(() => {
            //     console.log('用户退出插件')
            // })
            // ubWindow.webContents.on("this.$utools", this.$utools);
            // 向子窗口传递数据
            window.ipcRenderer.sendTo(ubWindow.webContents.id, "ping");
            console.log(1111);

            // require("electron").ipcRenderer.sendTo(
            //   ubWindow.webContents.id,
            //   "ping"
            // );
            // ubWindow.webContents.send("ping");

            // 执行脚本
            ubWindow
              .executeJavaScript(
                'fetch("https://jsonplaceholder.typicode.com/users/1").then(resp => resp.json())'
              )
              .then((result) => {
                console.log(result); // Will be the JSON object from the fetch call
              });
          }
        );
        // console.log(ubWindow);

        // // 如果子进程未收到心跳，则一直发送
        // let ping = setInterval(function () {
        //     ipcRenderer.sendTo(ubWindow.webContents.id, "ping");

        //     // mainWindow.webContents.send('main-process-messages', 'show_window');

        // }, 2000)

        // ipcRenderer.on("closeSqlWindow", (event, data) => {
        //     console.log(event);
        //     console.log(data);
        //     clearInterval(ping)
        // });
      });
    });
  },
  methods: {},
};
</script>

<style lang="scss">
.home {
  height: 100vh;
  background: #fff;
}
</style>
